package com.example.webexcel.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.example.webexcel.domain.Student;
import com.example.webexcel.util.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

public class DataListener extends AnalysisEventListener<Student> {

    ArrayList<Student> students = new ArrayList<>();

    @Override
    public void invoke(Student student, AnalysisContext analysisContext) {
        students.add(student);
        if (students.size() % 5 == 0) {
            ExcelUtil.readExcel(students);
            students.clear();
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        System.out.println("读取完毕");
    }
}
